package io.renren.msg.server;

import io.renren.msg.HelloAbsAioHandler;
import io.renren.msg.HelloPacket;
import org.tio.core.ChannelContext;
import org.tio.server.intf.ServerAioHandler;

import java.io.UnsupportedEncodingException;

/**
 * Created by kun on 2017/5/2.
 */
public class HelloServerAioHandler extends HelloAbsAioHandler implements ServerAioHandler<Object, HelloPacket, Object> {
    @Override
    public Object handler(HelloPacket packet, ChannelContext<Object, HelloPacket, Object> channelContext) throws UnsupportedEncodingException {
        byte[] body = packet.getBody();
        if (body != null) {
            recive(packet.getBody());
        }
        return null;
    }

    public static void recive(byte[] body) throws UnsupportedEncodingException {
        if (body != null) {
            String str = new String(body, HelloPacket.CHARSET);
            System.out.println("收到消息:" + str);
        }
    }
}
